define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		function get_data_goods_search(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"goods": [' +
					'{"goods_id": 1,"name": "螺丝刀","bn": "新品","store": 100,"price": 10.55,"buy_count": 20,"uptime": "2017/01/01 09:00:00","store_id": 1,"image_default": "img/upload/pro-img01.jpg","freez": 10,"is_tui": true,"is_new": true},' +
					'{"goods_id": 2,"name": "螺丝刀","bn": "热卖","store": 100,"price": 11.55,"buy_count": 20,"uptime": "2017/01/01 09:00:00","store_id": 2,"image_default": "img/upload/pro-img01.jpg","freez": 10,"is_tui": true,"is_new": false}]},' +
					'"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		};

		//品牌一览
		function get_data_brands(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"brand": [' +
					'{"id": "001","name": "世达"},' +
					'{"id": "002","name": "博士"}' +
					']},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		};

		//返回信息
		return {
			//商品数据
            goods_search: function(key, nPage, pagelimit, orderby, filter, marketable, callback, calldone) {
                Http.post({
                    method: 'goods.insales.search',
                    key:key,
                    nPage: nPage,
                    pagelimit:pagelimit,
                     orderby: orderby,
                    filter:filter,//商品检索的条件
                    marketable:marketable
                }, function(result) {
                     if(callback)
                     callback(get_data_goods_search(result).result);
                }, function(e) {

                }, function() {
					if(calldone)
						calldone();
                })
            },
			//修改库存
			change_store: function(goods_id, product_id, num, callback) {
				Http.post({
					method: 'goods.change.store',
					goods_id: goods_id,
					product_id: product_id,
					num: num
				}, function(result) {
					if(callback)
                     	callback(result);
				}, function(e) {

				}, function() {

				})
			},
			//修改价格
			change_price: function(goods_id, product_id, price, callback) {
				Http.post({
					method: 'goods.change.price',
					goods_id: goods_id,
					product_id: product_id,
					price: price
				}, function(result) {
					if(callback)
                     	callback(result);
				}, function(e) {

				}, function() {

				})
			},
			//删除商品
			delete_goods: function(goods_id, callback) {
				Http.post({
					method: 'goods.goods.delete',
					goods_id: goods_id
				}, function(result) {
					if(callback)
                     	callback(result);
				}, function(e) {

				}, function() {

				})
			},
			//上下架商品
			update_goods: function(goods_id, marketable, callback) {
				Http.post({
					method: 'goods.marketable.update',
					goods_id: goods_id,
					marketable: marketable
				}, function(result) {
					if(callback)
                     	callback(result);
				}, function(e) {

				}, function() {

				})
			},
			//品牌管理
            brand_list: function(callback) {
                Http.post({
                    method: 'goods.brand.getlist',
                }, function(result) {
                    if(callback)
                    callback(get_data_brands(result).result);
                }, function(e) {

                }, function() {

                })
            }
            
		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Productmanager_waitsale_edit", factory);
});